﻿@{
    ViewBag.Title = "UseCar";
    ViewBag.First = "车辆管理";
    ViewBag.Second = "用车申请";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";
    var list = ViewData["type"] as IList<Sc.Domain.BaseItem>;
}
<script src="~/Content/laydate-v1.1/laydate/laydate.js"></script>
<script type="text/javascript">
    $(document).ready(function (e) {
        initDate("txtStartTime", "txtExDate","YYYY/MM/DD hh:mm:ss");
    });

    //数据保存
    function Save() {
        var txtStartAddress = $("#txtStartAddress").val();
        var txtEndAddress = $("#txtEndAddress").val();
        var txtStartTime = $("#txtStartTime").val();
        var txtExDate = $("#txtExDate").val();
        var txtTotalCount = $("#txtTotalCount").val();
        var txtZcTonnage = $("#txtZcTonnage").val();
        var txtReson = $("#txtReson").val();
        var cbx = $("#txtIsApproal")[0].checked;
        if (txtStartAddress.length <= 0) {
            Tips("出发地不能为空", "txtStartAddress");
            return false;
        }
        if (txtEndAddress.length <= 0) {
            Tips("到达地不能为空", "txtEndAddress");
            return false;
        }
        if (txtStartTime.length <= 0) {
            Tips("出发时间不能为空", "txtStartTime");
            return false;
        }
        if (txtExDate.length <= 0) {
            Tips("返程时间不能为空", "txtExDate");
            return false;
        }
        if (isNaN(txtTotalCount) && checkNum(txtZcTonnage)) {
            Tips("乘车人数和载货吨位至少填写一个", "txtTotalCount");
            return false;
        }
        if (txtReson.length <= 0) {
            Tips("用车事由不能为空", "txtReson");
            return false;
        }
        var url = '@Url.Action("SaveUseCar")?' + $("#formData").serialize() + "&IsApproal=" + cbx;
        var load = loadTip('数据提交中，请稍后', 16, 0);
        $.post(url, function (data) {
            if (data > 0) {
                layer.msg('用车申请创建成功', { icon: 1, time: 1000, shade: [0.3, '#000'] }, function () {
                    layer.closeAll();
                    document.getElementById("formData").reset();
                });
            }
        });
    }

    function checkNum(val) {
        var re = /^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/;
        if (!re.test(val)) {
            return false;
        }
        return true;
    }
    //返回
    function back() {
        window.location.href = "@Url.Action("Index")";
    }
</script>
<style type="text/css">
    b {
        color: #d70101;
        margin-left: 2px;
    }
</style>
<div class="place" style="padding:2px;">
    <input type="button" name="button" class="btn82 btn_save2" value="保存" onclick="Save();">
</div>
<div class="formbody">
    <div class="formtitle"><span>用车申请</span></div>
    <form method="post" enctype="multipart/form-data" class="jqtransform" id="formData">
        <table style="width:98%;margin-left:20px;line-height:48px;">
            <tr>
                <td><label>出发地</label><b>*</b></td>
                <td><input name="StartAddress" type="text" class="dfinput" id="txtStartAddress" /></td>
                <td><label>目的地</label><b>*</b></td>
                <td><input name="EndAddress" type="text" class="dfinput" id="txtEndAddress" /></td>
            </tr>
            <tr>
                <td><label>出发时间</label><b>*</b></td>
                <td><input name="StartTime" type="text" class="dfinput" id="txtStartTime" /></td>
                <td><label>预计返程时间</label><b>*</b></td>
                <td><input name="ExDate" type="text" class="dfinput" id="txtExDate" /></td>
            </tr>
            <tr>
                <td><label>乘车人数</label><b>*</b></td>
                <td><input name="TotalCount" type="text" class="dfinput" id="txtTotalCount" /></td>
                <td><label>载重吨位</label><b>*</b></td>
                <td><input name="ZcTonnage" type="text" class="dfinput" id="txtZcTonnage" /></td>
            </tr>
            <tr>
                <td><label>用车事由</label><b>*</b></td>
                <td><input name="Reson" type="text" class="dfinput" id="txtReson" /></td>
                <td><label>备注</label><b>*</b></td>
                <td><input name="Remark" type="text" class="dfinput" id="txtRemark" /></td>
            </tr>
            <tr>
                <td><label>是否审核</label><b></b></td>
                <td><input type="checkbox" id="txtIsApproal" /></td>
            </tr>
        </table>
    </form>
</div>
